package xuegao.study.mall.admin.component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import xuegao.study.mall.common.api.CommonResult;

/**
 * 全局异常拦截器,处理全局异常
 */
@ControllerAdvice
public class GlobalException {

    private Logger log = LoggerFactory.getLogger(GlobalException.class);

    @ResponseBody
    @ExceptionHandler(value = Exception.class)
    public CommonResult handleRuntimeException(Exception e) {
        log.error("method invoke error", e);
        String errMsg = e.getMessage();
        return CommonResult.failed(errMsg);
    }
}